#!/usr/bin/env bash
#########################################################################
# File Name   : config_keystone.sh.j2
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Mon 2024-09-30 09:26:47(+0800)
#########################################################################

#
#
# Usage:

{
  set -euo pipefail
  # set -E
  #     If set, any trap on ERR is inherited by shell functions, command
  #     substitutions, and commands executed in a subshell environment.

  export TZ="Asia/Shanghai"
  APP_ROOT=$(dirname "$(readlink -fm "$0")")
  cd "${APP_ROOT}"
}

# create tables
# OK to ignore the error ['NoneType' object has no attribute 'getcurrent']
su -s /bin/bash keystone -c "keystone-manage db_sync"
# initialize Fernet key
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
# define keystone API Host
export controller={{ inventory_hostname }}
# bootstrap keystone
# set any password for [adminpassword] section
keystone-manage bootstrap --bootstrap-password {{ service_password }} \
  --bootstrap-admin-url https://$controller:5000/v3/ \
  --bootstrap-internal-url https://$controller:5000/v3/ \
  --bootstrap-public-url https://$controller:5000/v3/ \
  --bootstrap-region-id RegionOne
